package stream;

import java.util.HashMap;
import java.util.Map;

public class VideoConstraints {
    private final MediaTrackConstraints constraints;
    private final RTCRtpEncoding encodings;

    public VideoConstraints(MediaTrackConstraints constraints, RTCRtpEncoding encodings) {
        this.constraints = constraints;
        this.encodings = encodings;
    }

    public static Map<String, VideoConstraints> getVideoConstraints() {
        Map<String, VideoConstraints> constraints = new HashMap<>();
        MediaTrackConstraints qvgaMediaConstraints = new MediaTrackConstraints(new FrameRate(15, 30), 320, 180);
        RTCRtpEncoding qvgaEncodingConstraints = new RTCRtpEncoding(150000, 15);
        VideoConstraints qvgaVideoConstraints = new VideoConstraints(qvgaMediaConstraints, qvgaEncodingConstraints);
        constraints.put(Resolution.QVGA, qvgaVideoConstraints);

        MediaTrackConstraints vgaMediaConstraints = new MediaTrackConstraints(new FrameRate(30, 60  ), 640, 360);
        RTCRtpEncoding vgaEncodingConstraints = new RTCRtpEncoding(500000, 30);
        VideoConstraints vgaVideoConstraints = new VideoConstraints(vgaMediaConstraints, vgaEncodingConstraints);
        constraints.put(Resolution.VGA, vgaVideoConstraints);

        MediaTrackConstraints hdMediaConstraints = new MediaTrackConstraints(new FrameRate(30, 60  ), 1280, 720);
        RTCRtpEncoding hdEncodingConstraints = new RTCRtpEncoding(2500000, 30);
        VideoConstraints hdVideoConstraints = new VideoConstraints(hdMediaConstraints, hdEncodingConstraints);
        constraints.put(Resolution.HD, hdVideoConstraints);

        return constraints;
    }

    public MediaTrackConstraints getConstraints() {
        return constraints;
    }

    public RTCRtpEncoding getEncodings() {
        return encodings;
    }
}

